{
  "nbformat": 4,
  "nbformat_minor": 0,
  "metadata": {
    "colab": {
      "name": "Boostmonoculardepth.ipynb",
      "provenance": [],
      "collapsed_sections": []
    },
    "kernelspec": {
      "name": "python3",
      "display_name": "Python 3"
    },
    "language_info": {
      "name": "python"
    },
    "accelerator": "GPU"
  },
  "cells": [
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "Vy3Sy5fxAApC"
      },
      "source": [
        "#Boosting Monocular Depth Estimation Models to High-Resolution via Content-Adaptive Multi-Resolution Merging\n",
        "\n",
        "This Colab Notebook contains an inference on the implementation from https://github.com/compphoto/BoostingMonocularDepth.\n",
        "\n",
        "It supports using [MiDas-v2][1] and [LeRes][2] but not [SGRnet][3].\n",
        "\n",
        "\n",
        "### Instructions\n",
        "0. Ensure using a GPU by setting \"Runtime/change runtime type\" to GPU\n",
        "1. Run code section 1\n",
        "2. Put your test images inside /content/inputs\n",
        "3. Run code section 2 :  it will download the needed model weights for both [MiDas-v2][1] and [LeRes][2]. \n",
        "\n",
        "5. Run code section 3\n",
        "4. Run code section \"Ours with MiDas\" or \"Ours with LeRes\" to generate the results \n",
        "3. Results will be generated in /content/outputs_midas or /content/outputs_leres folders. \n",
        "\n",
        "\n",
        "[1]: https://github.com/intel-isl/MiDaS/tree/v2\n",
        "[2]: https://github.com/aim-uofa/AdelaiDepth/tree/main/LeReS\n",
        "[3]: https://github.com/KexianHust/Structure-Guided-Ranking-Loss"
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "Q3HwE8ZNTBhh"
      },
      "source": [
        "# Code section 1\n",
        "\n",
        "!mkdir -p inputs\n",
        "!mkdir -p outputs_midas\n",
        "!mkdir -p outputs_leres"
      ],
      "execution_count": null,
      "outputs": []
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "gUvYYzbz-D9k"
      },
      "source": [
        "# Code section 2\n",
        "\n",
        "\n",
        "# Clone git repo\n",
        "!git clone https://github.com/compphoto/BoostingMonocularDepth.git\n",
        "\n",
        "!wget https://sfu.ca/~yagiz/CVPR21/latest_net_G.pth\n",
        "#!gdown https://drive.google.com/u/0/uc?id=1cU2y-kMbt0Sf00Ns4CN2oO9qPJ8BensP&export=download\n",
        "\n",
        "# Downloading merge model weights\n",
        "!mkdir -p /content/BoostingMonocularDepth/pix2pix/checkpoints/mergemodel/\n",
        "!mv latest_net_G.pth /content/BoostingMonocularDepth/pix2pix/checkpoints/mergemodel/\n",
        "\n",
        "# Downloading Midas weights\n",
        "!wget https://github.com/AlexeyAB/MiDaS/releases/download/midas_dpt/midas_v21-f6b98070.pt\n",
        "!mv midas_v21-f6b98070.pt /content/BoostingMonocularDepth/midas/model.pt\n",
        "\n",
        "# # Downloading LeRes weights\n",
        "!wget https://cloudstor.aarnet.edu.au/plus/s/lTIJF4vrvHCAI31/download\n",
        "!mv download /content/BoostingMonocularDepth/res101.pth"
      ],
      "execution_count": null,
      "outputs": []
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "JbgaIYODQ3jd"
      },
      "source": [
        "# Code section 3\n",
        "%cd BoostingMonocularDepth/"
      ],
      "execution_count": null,
      "outputs": []
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "76wqxTAbVyeP"
      },
      "source": [
        "> After execution of Code section 3 you can run the following code sections multiple times to generate results but **do not run the previous code sections**. If you did so by mistake use \"Runtime/ Reset factory runtime\" and then start from step 0."
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "ZzcDgJfc9zrW"
      },
      "source": [
        "# Running the method using MiDas\n",
        "!python run.py --Final --data_dir /content/inputs --output_dir  /content/outputs_midas/ --depthNet 0"
      ],
      "execution_count": null,
      "outputs": []
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "FNfFz3e4Qxdr"
      },
      "source": [
        "# Running the method using LeRes\n",
        "!python run.py --Final --data_dir /content/inputs --output_dir  /content/outputs_leres/ --depthNet 2"
      ],
      "execution_count": null,
      "outputs": []
    }
  ]
}
